package com.dream.service.recommender.splitter.strage.impl;

import com.dream.service.recommender.domain.splitter.SplitterRequest;

import java.util.concurrent.atomic.AtomicLong;

/**
 * Created by zhiji on 2016/3/15.
 * 轮询策略
 */
public class RoundStrategy extends BaseStrategy {

    private AtomicLong atomicLong = new AtomicLong(0);

    public AtomicLong getAtomicLong() {
        return atomicLong;
    }

    public void setAtomicLong(AtomicLong atomicLong) {
        this.atomicLong = atomicLong;
    }

    @Override
    public int getSeed(SplitterRequest splitterRequest) {
        if(atomicLong.longValue()>=Long.MAX_VALUE){
            atomicLong.set(0);
        }
        return (int) (atomicLong.getAndIncrement() % maxtraffic);
    }

}
